package com.turbo.cloud.core.api;


/**
 * 返回结果类
 */
public class R {
    /**
     * 请求成功
     */
    public static <T> Result<T> success() {
        return success(ResultCode.SUCCESS.getMessage());
    }

    /**
     * 请求成功
     *
     * @param message 描述
     */
    public static <T> Result<T> success(String message) {
        Result<T> result = new Result<>();
        result.setCode(ResultCode.SUCCESS.getCode()).setMessage(message);
        return result;
    }

    /**
     * 请求成功
     * @param resultData 数据
     */
    public static <T> Result<T> result(T resultData) {
        Result<T> result = success();
        return result.setResult(resultData);
    }

    /**
     * 请求失败
     */
    public static <T> Result<T> failed() {
        return failed(ResultCode.FAILED.getMessage());
    }

    /**
     * 请求成功
     * @param message 描述
     */
    public static <T> Result<T> failed(String message) {
        Result<T> result = new Result<>();
        result.setCode(ResultCode.FAILED.getCode()).setMessage(message);
        return result;
    }

    /**
     * 未登录返回结果
     */
    public static <T> Result<T> unauthorized() {
        Result<T> result = new Result<>();
        result.setCode(ResultCode.UNAUTHORIZED.getCode()).setMessage(ResultCode.UNAUTHORIZED.getMessage());
        return result;
    }

    /**
     * 未登录返回结果
     * @param message 描述
     */
    public static <T> Result<T> unauthorized(String message) {
        Result<T> result = new Result<>();
        result.setCode(ResultCode.UNAUTHORIZED.getCode()).setMessage(message);
        return result;
    }

    /**
     * 未授权返回结果
     */
    public static <T> Result<T> forbidden() {
        Result<T> result = new Result<>();
        result.setCode(ResultCode.FORBIDDEN.getCode()).setMessage(ResultCode.FORBIDDEN.getMessage());
        return result;
    }

    /**
     * 未授权返回结果
     * @param message 描述
     */
    public static <T> Result<T> forbidden(String message) {
        Result<T> result = new Result<>();
        result.setCode(ResultCode.FORBIDDEN.getCode()).setMessage(message);
        return result;
    }
}
